#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1e5 + 10, INF = 1e9;

int n, m;
struct Node{
    int s[2], p, v, size;

    void init(int _v, int _p){
        p = _p;
        v = _v;
        size = 1;
    }
}node[N];

int root, idx;

void pushup(int x){
    node[x].size = node[node[x].s[0]].size + node[node[x].s[1]].size + 1;
}

void rotate(int x){
    int y = node[x].p, z = node[y].p;
    int k = (node[y].s[1] == x);
    node[z].s[node[z].s[1] == y] = x, node[x].p = z;
    node[y].s[k] = node[x].s[k ^ 1], node[node[x].s[k ^ 1]].p = y;
    node[x].s[k ^ 1] = y, node[y].p = x;
    pushup(y), pushup(x);
}


void splay(int x, int k){
    while(node[x].p != k){
        int y = node[x].p, z = node[y].p;
        if(z != k){
            if((node[z].s[1] == y) ^ (node[y].s[1] == x)){
                rotate(x);
            }else{
                rotate(y);
            }
        }
        rotate(x);
    }

    if(!k) root = x;
}


int insert(int v){
    int u = root, p = 0;
    while(u){
        p = u;
        u = node[u].s[node[u].v < v];
    }
    u = ++idx;
    if(p) node[p].s[node[p].v < v] = u;
    node[u].init(v, p);
    splay(u, 0);
    return u;
}


int get(int val){
    int u = root, res = 0;
    while (u)
    {
        if(node[u].v >= val) res = u, u = node[u].s[0];
        else u = node[u].s[1];
    }
    return res;
}


int get_k(int k){
    int u = root, p = 0;
    while(u){
        if(node[node[u].s[0]].size >= k) u = node[u].s[0];
        else if(node[node[u].s[0]].size + 1 == k) return node[u].v;
        else {
            k -= node[node[u].s[0]].size + 1;
            u = node[u].s[1];
        }
    }
    return -1;
}


// k + delta < m
int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int tot = 0, delta = 0;
    int L = insert(-INF),  R = insert(INF);

    scanf("%d%d", &n, &m);

    char op[2];
    int k;
    while(n --){
        scanf("%s%d", op, &k);
        if(*op == 'I'){
            if(k >= m){
                k -= delta;
                insert(k);
                tot++;
            }
        }else if(*op == 'A'){
            delta += k;
        }else if(*op == 'S'){
            delta -= k;
            R = get(m - delta);
            splay(R, 0), splay(L, R);
            node[L].s[1] = 0;
            pushup(L), pushup(R);
        }else{
            if (node[root].size - 2 < k) puts("-1");
            else printf("%d\n", get_k(node[root].size - k) + delta);
        }

    }

    printf("%d\n", tot - (node[root].size - 2));
    return 0;
}